#region Copyright Notice

// 
// 
//  
//  Copyright (c) 2009-2011 Anindya Chatterjee
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//      http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// 
// 

#endregion

using System;
using System.Globalization;
using System.IO;
using System.Linq;
using Shell32;

namespace AbstractClass.IO
{
    /// <summary>
    /// Represents an item in the Recycle Bin.
    /// </summary>
    public class RecycledItem
    {
        /// <summary>
        /// Gets the name of the item.
        /// </summary>
        /// <value>The name of the item.</value>
        public string Name { get; internal set; }

        /// <summary>
        /// Gets the type of the item.
        /// </summary>
        /// <value>The item type.</value>
        public string ItemType { get; internal set; }

        /// <summary>
        /// Gets the size of the item.
        /// </summary>
        /// <value>The item's size.</value>
        public string Size { get; internal set; }

        /// <summary>
        /// Gets the origin of the item.
        /// </summary>
        /// <value>The item origin.</value>
        public DirectoryInfo Origin { get; internal set; }

        /// <summary>
        /// Gets the delete time.
        /// </summary>
        /// <value>The delete time.</value>
        public DateTime Deleted { get; internal set; }

        /// <summary>
        /// Gets the last modified time.
        /// </summary>
        /// <value>The last modified time.</value>
        public DateTime Modified { get; internal set; }

        /// <summary>
        /// Gets the attribute of the item.
        /// </summary>
        /// <value>The attribute of the item.</value>
        public string Attribute { get; internal set; }

        internal FolderItem FolderItem { get; set; }

        /// <summary>
        ///   Returns a <see cref = "System.String" /> that represents this <see cref = "string" />.
        /// </summary>
        /// <returns>
        ///   A <see cref = "System" /> that represents this <see cref = "RecycleBin" />.
        /// </returns>
        public override string ToString()
        {
            return Name;
        }

        /// <summary>
        /// Restores the deleted item from the Recycle Bin.
        /// </summary>
        public void Restore()
        {
            if (FolderItem == null) return;
            foreach (FolderItemVerb fiVerb in
                FolderItem.Verbs().Cast<FolderItemVerb>().Where(
                    fiVerb =>
                    fiVerb.Name.ToUpper().Contains(
                        LanguageResource.RecycledItemRestore.ToUpper(CultureInfo.CurrentCulture))))
            {
                fiVerb.DoIt();
                return;
            }
            FolderItem.Verbs().Item(0).DoIt();
        }

        /// <summary>
        /// Removes an item from the Recycle Bin showing a confirmation system dialog box.
        /// </summary>
        [Obsolete("It shows a Windows native confirmation dialog box before deleting.")]
        public void Delete()
        {
            if (FolderItem == null) return;
            foreach (FolderItemVerb fiVerb in
                FolderItem.Verbs().Cast<FolderItemVerb>().Where(
                    fiVerb =>
                    fiVerb.Name.ToUpper().Contains(
                        LanguageResource.RecycledItemDelete.ToUpper(CultureInfo.CurrentCulture))))
            {
                fiVerb.DoIt();
                return;
            }
            FolderItem.Verbs().Item(2).DoIt();
        }
    }
}